package com.example.springboottestgit.controller;

import com.example.springboottestgit.bean.ResultMsg;
import com.example.springboottestgit.bean.dto.EconomicPolicyDTO;
import com.example.springboottestgit.service.ElasticSearchClientServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @description:
 * @author: ZZZ
 */
@RestController
public class ESController {
    @Autowired
    private ElasticSearchClientServer elasticSearchClientServer;

    @GetMapping("/es/create")
    public ResultMsg<Object> create(String indexName) throws IOException {
        elasticSearchClientServer.createIndex(indexName);
        return ResultMsg.success();
    }


    @GetMapping("/es/reload")
    public ResultMsg<Object> reload() {
        elasticSearchClientServer.reloadText();
        return ResultMsg.success();
    }

    @GetMapping("/es/del")
    public ResultMsg<Object> del_content_10000() {
        elasticSearchClientServer.del_content_10000();
        return ResultMsg.success();
    }

    @RequestMapping("/es/query")
    public ResultMsg<Object> queryContent(@RequestBody EconomicPolicyDTO dto) throws IOException {

        List<String> list = elasticSearchClientServer.queryContent("ep20251118", dto, 5);
        return ResultMsg.success(list);
    }

}
